#============================================================
#	Item Bean
#============================================================
#  基础物品数据类
#============================================================
# @datetime: 2022-5-10 00:37:29
#============================================================
class_name ItemBean


const Type = {
	NORMAL = "normal",
	WEAPON = "weapon",
	CONSUMABLES = "consumables",
}


var id : String = ""
var count : int = -1

var name : String
var path : String setget set_path
var desc : String
var type : String
var icon : String setget set_icon
var level_desc : Array
var texture : Texture


func set_path(value: String) -> void:
	path = value
	if not ResourceLoader.exists(value):
		var dir : Directory = Directory.new()
		var filename : String = path.get_file()
		var item_path : String = "res://src/assets/pixel/items"
		for p in [
			item_path + "/weapon",
			item_path + "/potion",
			item_path + "/shield",
			item_path + "/chest",
			item_path + "/flag",
		]:
			if dir.file_exists(p.plus_file(filename)):
				path = p.plus_file(filename)
				break
	
	texture = load(path)


func set_icon(value: String) -> void:
	icon = value
	if ResourceLoader.exists(value):
		texture = load(value)

